package com.feeyo.groundservice.composewidget.view.calendar

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.text.font.FontWeight
import com.feeyo.groundservice.composewidget.util.dimenToDp
import com.feeyo.groundservice.composewidget.util.dimenToSp
import com.feeyo.groundservice.composewidget.util.intervalClick
import com.feeyo.groundservice.composewidget.util.toComposeColor
import com.feeyo.groundservice.composewidget.view.util.HorizontalSpace
import com.feeyo.groundservice.composewidget.R

/**
 *作者：70893 on 2025-03-09
 *描述：底部日历布局：已完成  航班列表
 */


@Composable
fun BottomCalendar(
    time: String,
    onPre: () -> Unit,
    onCalendar: () -> Unit,
    onNext: () -> Unit,
    onRefresh: () -> Unit,
    modifier: Modifier = Modifier
) {

    Row(
        modifier = Modifier.then(modifier).fillMaxWidth().height(R.dimen.d30.dimenToDp())
    ) {
        Spacer(modifier = Modifier.weight(1f))
        //左箭头
        ImageIconView(R.drawable.icon_white_left, onClick = onPre)
        HorizontalSpace(R.dimen.d15.dimenToDp())
        //日历
        ImageCalendarView(time, onClick = onCalendar)
        HorizontalSpace(R.dimen.d15.dimenToDp())

        //右箭头
        ImageIconView(R.drawable.icon_white_right, onClick = onNext)
        HorizontalSpace(R.dimen.d15.dimenToDp())
        //刷新
        ImageIconView(R.drawable.icon_refresh, onClick = onRefresh)
        HorizontalSpace(R.dimen.d15.dimenToDp())
    }
}


@Composable
private fun ImageIconView(resourceId: Int, onClick: () -> Unit) {
    Box(
        modifier = Modifier.size(R.dimen.d30.dimenToDp())
            .background(
                color = R.color.black_131313_alphacc.toComposeColor(),
                shape = RoundedCornerShape(R.dimen.d3.dimenToDp())
            ).intervalClick { onClick() },
        contentAlignment = Alignment.Center
    ) {
        Image(
            painter = painterResource(resourceId),
            contentDescription = null,
        )
    }
}

@Composable
private fun ImageCalendarView(time: String, onClick: () -> Unit) {
    Box(
        modifier = Modifier.size(R.dimen.d30.dimenToDp())
            .background(
                color = R.color.black_131313_alphacc.toComposeColor(),
                shape = RoundedCornerShape(R.dimen.d3.dimenToDp())
            ).intervalClick { onClick() },
    ) {
        Image(
            painter = painterResource(R.drawable.icon_white_calendar),
            contentDescription = null,
            contentScale = ContentScale.FillHeight,
            modifier = Modifier.size(R.dimen.d20.dimenToDp()).align(Alignment.Center)
        )
        Text(
            text = time,
            color = R.color.white.toComposeColor(),
            fontSize = R.dimen.d10.dimenToSp(),
            fontWeight = FontWeight.W400,
            modifier = Modifier.align(Alignment.BottomCenter)
                .padding(bottom = R.dimen.d7.dimenToDp())
        )
    }
}